package com.ted.zookeeperMap;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

public class ExpirationWatcher implements Watcher {

    private final Runnable runnable;


    public ExpirationWatcher(Runnable runnable) {
        this.runnable = runnable;
    }


    @Override
    public void process(WatchedEvent watchedEvent) {
        if (watchedEvent.getType() == Event.EventType.None && watchedEvent.getState() == Event.KeeperState.Expired) {
            runnable.run();
        }

    }
}
